No SoundBlaster Board Sounds
If you have an old Laptop or PC with no Sound Blaster board installed, the following demonstrates how to generate a variety of tones, using the internal speaker in the console. Even if a system does have a SB board, I know of at least three people around my age (70) who rarely switch on the stereo speakers, or even plug then in! This is why my the small auction DB I designed primarily for one of these old folk, has an option to produce sounds from either speaker system, but he still insists on using the QB DOS version at our club auctions, because he cannot be bothered to use the mouse during an auction!
Although the following example is a game intended for the young, the principles can easily be applied to any program, to replace the normal beep sounds etc that can only be produced if a SB board if installed. Likewise a substitute for the Windows Welcome opening sound could be produced if added to the Startup, although I must admit I prefer to use a much smaller QB DOS version.
Note:
The program requires a single
graphic file of a ship. It
and the scource code are part
of the newsletter archive.
Like most of my LB efforts this relies on a routine kindly provided by others, such as in the [spkr] section that produces the tones. You will also notice the WindowWidth and WindowHeight have been set very small to match the display on an old Laptop I have still.
by Gordon Sweet
' DEMO of sounds for Laptops etc with no SB board
' Needs DESTROYER.BMP sprite
nomainwin
ux = 1 : uy = 1
if DisplayWidth > 1000 then ux = 200 : uy = 120
UpperLeftX = ux : UpperLeftY = uy
WindowWidth = 640 : WindowHeight = 480
button #s, "<--", [left], UL, 256, 424
button #s, "FIRE", [fire], UL, 296, 424
button #s, "-->", [right], UL, 344, 424
open "SUBHUNT" for graphics_nsb as #s
#s "trapclose [quit]; fill 0 50 50; backcolor 0 50 50"
#s "color cyan; font arial 12; down"
for wave = 1 to 400
xwave=int(rnd(1)*560)+50
ywave=int(rnd(1)*400)+30
#s "place ";xwave;" ";ywave
#s "\~"
next wave
#s "getbmp drawing 1 1 560 400" ' Retain sea background
loadbmp "ship", "destroyer.bmp"
#s "font arial 24 bold; place 180 80"
#s "\ SUBMARINE HUNT. "
#s "font arial 14 bold; place 130 160"
#s "\The Sub will only be seen briefly only once."
#s "\It will fire a torpedoe, and then move a little."
#s "\Move the Destroyer then fire a Depth Charge."
#s "\";space$(10);"Game ends when either are hit."
#s "\\";space$(15);"CLICK FIRE TO BEGIN."
gosub [doh] : turn = 0 : wait
[go]
shot = 1 : gosub [ping]
#s "background drawing";
#s "addsprite ship ship"
spos = 200 ' destroyer sprite
#s "spritexy ship ";spos-25;" 384"
#s "drawsprites"
' submarine
#s "color lightgray; size 6; line 350 30 380 30"
#s "set 365 25; size 2; set 357 27; line 367 25 367 19"
#s "size 1; line 353 25 357 25"
for n = 1 to 4 : gosub [bang] : next n
#s "backcolor 0 50 50; color 0 50 50" ' hide submarine
#s "place 342 16; boxfilled 388 38"
battle = 1 : turn = 1
#s "size 2"
subm = 365 : x = subm
while battle = 1
for y = 40 to 464 step 10
if x>spos-25 and x390 then [hit]
#s "color yellow; line ";x;" ";y;" ";x;" ";y+4
gosub [torp]
#s "color 0 50 50; line ";x;" ";y;" ";x;" ";y+4
next y
[destroyer]
#s "spritexy ship ";spos-25;" 384"
#s "drawsprites"
wait
[shoot]
x = spos : freq = 1500 : turn = 2
for y = 350 to 0 step -10
if x>subm-15 and x 10 then spos = spos - 10
goto [destroyer]
[right]
if turn = 0 then wait
if spos < 560 then spos = spos + 10
goto [destroyer]
[submove] ' move submarine
move = int(rnd(1)*80)+20-(int(rnd(1)*80)+20)
subm = subm + move : x = subm
if x < 20 or x > 560 then [submove]
return
[hit]
#s "color red; size 20; set ";x;" ";y
gosub [bang] : battle = 0 : y = 0
goto [done]
[doh]
freq = 1500 : delay = 200
for n = 1 to 3
gosub [spkr]
next n
return
[bang]
freq = 60 : delay = 500 : gosub [spkr]
return
[ping]
freq = 800 : delay = 200 : gosub [spkr]
return
[dchg]
delay = 100 : gosub [spkr]
return
[torp]
freq = 2000 : delay = 100 : gosub [spkr]
return
[spkr]
cf=int(1193180/freq)
loByte=int(Mod(cf,256))
hiByte=int(cf/256)
out 67,182 'enable timer chan2 for tone generator
out 66,loByte 'load timer counter with low byte
out 66,hiByte 'load timer counter with high byte
out 97, 3 'internal spkr on
d = delay : gosub [delay]
out 97,0 'internal spkr off
d = 1 : gosub [delay]
return
function Mod(number, divisor)
Mod=(number)-(int(number/divisor)*divisor)
end function
[delay]
tim = time$("ms")
while time$("ms") < tim + d
wend : return
[quit]
close #s : end